namespace ghost
{
    /**文字动画提示*/
    export class TextTip extends Laya.Text
    {
        public static show(msg:string):void
        {
            let tip:TextTip;
            if(TextTip.pool.length == 0)
                tip = new TextTip;
            else
                tip = TextTip.pool.pop();
            tip.show(msg);
        }        
        private static usingArr:TextTip[]=[];
        public static pool:TextTip[]=[];
        public inPool:boolean;
        public lab:Laya.Text;                
        private _flowY:number;
        private _tweenY:number;
        constructor()
        {
            super();
            let s = this;            
            s.color = "#fff000";
            s.fontSize = 30;            
            s.text = "0";
            s.stroke = 6;
            s.strokeColor = "#000000";
            s.align = "center";
            s.width = GameManager.DESIGN_WIDTH;
            s.y = 4;
            s.x = 40;
            s._flowY = 0;
        }
        public set tweenY(val:number)
        {
            this._tweenY = val;
            this.y = this._tweenY - this._flowY;
        }
        public get tweenY():number
        {
            return this._tweenY;
        }
        public show(msg:string):void
        {
            let s = this;
            let module:Module;            
            module = Module.getInstance();
            s.text = msg;            
            module.addChild(s);
            s.x = module.width - s.width >> 1;
            s.tweenY = module.frameBound.y + (module.frameBound.height - s.width >> 1);
            
            let len:number,toY:number;
            let padding:number = 26;
            toY = padding;
            len = TextTip.usingArr.length;
            while(--len>-1)
            {
                TextTip.usingArr[len]._flowY = toY;
                TextTip.usingArr[len].tweenY = TextTip.usingArr[len]._tweenY;
                toY += padding;
            }
            s.alpha = 1;  
            s._flowY = 0;          
            TextTip.usingArr.push(s);
            GYTween.to(s, [
                TweenData.getInstance("tweenY", s._tweenY - 50),
                TweenData.getInstance("alpha", 0)
            ], 1000, 0, s, ()=>{                
                s.inPool = true;
                let ind:number = TextTip.usingArr.indexOf(s);
                TextTip.usingArr.splice(ind, 1);
                TextTip.pool.push(s);                
            });
        }        
    }
}